home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0574.ZIP / STRCMP.ASM < prev    next >
Assembly Source File  |  1986-11-20  |  791b  |  52 lines

  1. include compiler.inc
  2.     ttl    STRCMP, 1.04, 08-30-86, clr
  3.  
  4. ;string function - compares strings, returns - if first smaller,
  5. ;            0 if equal, + if first larger.
  6.  
  7.     dseg
  8.  
  9.     cseg
  10.  
  11.     procdef    strncmp, <<string1, ptr>, <string2, ptr>, <cnt, word>>
  12.     mov    cx,cnt
  13.     jmp    short start
  14.  
  15.     entrdef    strcmp
  16.     mov    cx,7fffh
  17.  
  18. start:
  19.     pushreg
  20.     pushds
  21.  
  22.     xor    ax,ax
  23.     jcxz    endit
  24.     ldptr    si,string1
  25.     ldptr    di,string2
  26.     cld
  27.     dec    di
  28. cmpr:
  29.     lodsb            ; check s1 char
  30.     inc    di
  31.     or    al,al        ; test for EOS
  32.     jz    eos1
  33.     sub    al,[di]        ; compare to s2 char
  34.     jnz    getout
  35.     loop    cmpr        ; while equal close loop
  36. getout:
  37.     cbw            ; on failure extend sign bit
  38. ;
  39.     jmp    short endit            ; mismatched
  40.  
  41. eos1:
  42.     sub    al,[di]        ; 0 if ==, else signed
  43.     cbw            ; extend sign bit
  44. endit:
  45.     pret
  46.  
  47.     pend    strncmp
  48.  
  49.     finish
  50.  
  51.     end
  52.